/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.raflik.queryxml.ui;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JList;
import javax.swing.plaf.basic.BasicComboBoxRenderer;

/**
 *
 * @author raflik
 */
public class SelectableComboBoxRenderer extends BasicComboBoxRenderer {

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

        if (isSelected) {
            Color selectionBackground = list.getSelectionBackground();
            Color selectionForeground = list.getSelectionForeground();
            setBackground(selectionBackground);
            setForeground(selectionForeground);
        } else {
            Color background = list.getBackground();
            Color foreground = list.getForeground();
            setBackground(background);
            setForeground(foreground);
        }
        
        return this;
    }
}
